<template>
	<view class="parent">
		<view class="title" style="padding-top: 200rpx;">您的生日是？</view>

		<picker-view :indicator-style="indicatorStyle" :value="value" @change="bindChange" class="picker-view"
			mask-style="background:transparent;">
			<picker-view-column>
				<view class="item" :class="{ select: item == year }" v-for="(item, index) in years" :key="index">
					{{ item }}年
				</view>
			</picker-view-column>
			<picker-view-column>
				<view class="item" :class="{ select: item == month }" v-for="(item, index) in months" :key="index">
					{{ item }}月
				</view>
			</picker-view-column>
			<picker-view-column>
				<view class="item" :class="{ select: item == day }" v-for="(item, index) in days" :key="index">
					{{ item }}日
				</view>
			</picker-view-column>
		</picker-view>

		<register-bottom @next='next'></register-bottom>
	</view>
</template>

<script>
	import RouteUtil from '@/common/RouteUtil.js';
	export default {
		data() {
			const date = new Date();
			const years = [];
			const year = date.getFullYear();
			const months = [];
			const month = date.getMonth() + 1;
			const days = [];
			const day = date.getDate();
			for (let i = 1900; i <= date.getFullYear() - 18; i++) {
				years.push(i);
			}
			for (let i = 1; i <= 12; i++) {
				months.push(i);
			}
			for (let i = 1; i <= 31; i++) {
				days.push(i);
			}
			return {
				years,
				year,
				months,
				month,
				days,
				day,
				value: [years.length - 1, month - 1, day - 1],
				indicatorStyle: `height: 50px`,
				data: {
					sex: '',
					nick: '',
					birthday: '',
					heightId: '',
					weightId: '',
					careerId: '',
					incomeId: '',
					tagIds: '',
					educId: '',
					headPicId: '',
					prId: '',
					cityId: '',
					distId: '',
					passWord: '123456'
				},
			};
		},
		onLoad() {
			this.data = uni.getStorageSync('registerInfo');
			this.$nextTick(() => {
				let e = {
					detail: {
						value: this.value
					}
				};
				this.bindChange(e);
			});
		},
		methods: {
			back() {
				uni.navigateBack();
			},
			bindChange: function(e) {
				const val = e.detail.value;
				this.year = this.years[val[0]];
				this.month = this.months[val[1]];
				this.day = this.days[val[2]];
				this.data.birthday = this.years[val[0]] + '-' + this.months[val[1]] + '-' + this.days[val[2]];
			},
			async next() {
				let params = {
					nicheng: this.data.nick,
					sex: this.data.sex,
					shengri: this.data.birthday,
				}
				let res = await this.$common.post('/app/login/completeMaterial', params);
				if(0 == res.code){
					uni.setStorageSync('registerInfo', this.data);
					RouteUtil.toRegister3()
				}else {
					this.$common.showToast(res.msg)
				}
			},

		}
	};
</script>

<style lang="scss">
	.parent {
		padding: 0 50rpx;

		.title {
			font-weight: bold;
			font-size: 48rpx;
			color: #fff;
		}

		.picker-view {
			width: 100%;
			height: 600rpx;
			margin: 0 auto;
		}

		.item {
			height: 50px;
			line-height: 50px;
			text-align: center;
			color: #888;
		}

		.item.select {
			color: #eee;
			font-size: 36rpx;
			font-weight: 600;
		}

	}
</style>